package com.sskj.gocoin;

import android.app.Application;
import android.content.pm.ApplicationInfo;

import com.sskj.gocoin.common.App;
import com.sskj.gocoin.common.AppManager;
import com.sskj.gocoin.common.Cockroach;
import com.sskj.gocoin.common.Constants;
import com.sskj.gocoin.utils.SPUtils;
import com.sskj.gocoin.v.activity.MainActivity;


/**
 * Created by Lee on 2018/1/25 0025.
 */

public class MyAppLication extends Application {

    public static Application getApplication() {
        return App.INSTANCE;
    }


    private static MyAppLication mApplication;


    @Override
    public void onCreate() {
        super.onCreate();
        mApplication = this;
    }


    public static String getMobile() {
        return (String) SPUtils.get(App.INSTANCE, Constants.SP_MOBILE, "");
    }

    public static String getToken() {
        return (String) SPUtils.get(App.INSTANCE, Constants.SP_TOKEN, "");
    }

    public static String getAccount() {
        return (String) SPUtils.get(App.INSTANCE, Constants.SP_ACCOUNT, "");
    }

    public static boolean isLogin() {
        return (boolean) SPUtils.get(App.INSTANCE, Constants.SP_LOGIN_STATUS, false);
    }

    public static String getName() {
        return (String) SPUtils.get(App.INSTANCE, Constants.SP_REALNAME, "");
    }

    public static String getIdCard() {
        return (String) SPUtils.get(App.INSTANCE, Constants.SP_IDCORD, "");
    }

    public static String getJGCode() {
        return (String) SPUtils.get(App.INSTANCE, Constants.SP_JGCODE, "");
    }

    public static String getLANGUAGE() {
        return (String) SPUtils.get(App.INSTANCE, Constants.LANGUAGE, "zh", "zh");
    }

    public static int getGOOGLETYPE() {
        return (int) SPUtils.get(App.INSTANCE, Constants.GOOGLETYPE, 0);
    }

    public static String getUId() {
        return (String) SPUtils.get(App.INSTANCE, Constants.SP_UID, "");
    }

    /**
     * 实名认证状态
     */
    public static int getRealnameStatus() {
        return (int) SPUtils.get(App.INSTANCE, Constants.SP_REALNAME_STATUS, 0);
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        Cockroach.uninstall();
    }

    /**
     * 退出应用
     *
     * @param mainActivityClass
     */
    public static void exitApp(Class<MainActivity> mainActivityClass) {
        AppManager.getAppManager().finishAllActivity(mainActivityClass);
    }


    public boolean isDebug() {
        ApplicationInfo info = this.getApplicationInfo();
        return (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
    }
}
